package builder;

import builder.actors.DocumentDirector;
import builder.actors.HTMLBuilder;
import builder.actors.TextBuilder;

/**
 * @author chj
 * 类名：Main
 * 类型：具体类
 * 类含义：表示测试程序行为的对象
 */
public class Main{
    public static void main(String[] args) {
        if (args.length != 1) {
            usage();
            System.exit(0);
        }
        if (args[0].equals("plain")) {
            TextBuilder textBuilder = new TextBuilder();
            DocumentDirector documentDirector = new DocumentDirector(textBuilder);
            String title = "问候语";
            String string = "从早上至下午";
            String[] items = new String[]{"早上好。", "下午好。"};
            documentDirector.constructDocument(title, string, items);
            String result = textBuilder.getResult();
            System.out.println(result);
        } else if (args[0].equals("html")) {
            HTMLBuilder htmlBuilder = new HTMLBuilder();
            DocumentDirector documentDirector = new DocumentDirector(htmlBuilder);
            String title = "问候语";
            String string = "从早上至下午";
            String[] items = new String[]{"早上好。", "下午好。"};
            documentDirector.constructDocument(title, string, items);
            String filename = htmlBuilder.getResult();
            System.out.println(filename + "文件编写完成");
        } else {
            usage();
            System.exit(0);
        }
    }

    public static void usage() {
        System.out.println("Usage: java Main plain    编写纯文本文档");
        System.out.println("Usage: java Main html     编写HTML文档");
    }
}
